package com.bsoft.controller;

import com.bsoft.productor.Demo07Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

@RestController
@Slf4j
public class Demo08ProducerController {
    @Autowired
    private Demo07Producer demo07Producer;
    @GetMapping("/testSynSend01")
    public void  testSynSend01() throws InterruptedException {
         //不设置 消息的过期时间 使用默认的消息过期时间
        this.testSyncSendDelay(null);
    }
    @GetMapping("/testSynSend02")
    public void  testSynSend02() throws InterruptedException {
        //不设置 消息的过期时间 使用默认的消息过期时间
        this.testSyncSendDelay(null);
    }


    private void testSyncSendDelay(Integer o) throws InterruptedException {
       int id = (int) (System.currentTimeMillis()/1000);
        demo07Producer.syncSend(id,o);
        log.info("[testSyncSendDelay][发送编号：[{}] 发送成功]", id);
        //阻塞等待 保证消费
        new CountDownLatch(1).await();
    }

}
